package Test;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import AuthCode.AuthCodeServlet;

@WebServlet("/authcode")
public class TestServlet extends HttpServlet {
	
	private static final long serialVersionUID = 1L;
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String action = req.getParameter("action");
		String result ="";
		if(action.equals("log")) {
			result = test(req);
			System.out.println(result);
		}
		PrintWriter wr = resp.getWriter();
		wr.print(result);
		wr.flush();
		wr.close();
		wr = null;
		
	}
	
	private String test(HttpServletRequest req) {
		String authCode = req.getParameter("authCode");
		System.out.println(authCode);
		Object authCodeSession = req.getSession().getAttribute(AuthCodeServlet.name);
		System.out.println(authCodeSession);
		if(!authCodeSession.toString().equals(authCode)) {
			return "N";
		}
		return "Y";

	}
}
